package me.fung.rem.common

import java.io.File
import java.nio.charset.Charset

class LocalFile(
    private val _path: String,
    private val _charset: Charset = Charsets.UTF_8,
) {
    fun readFile(charset: Charset = _charset): String {
        val file = File(_path)
        if (!file.exists()) {
            file.writer().use { it.write("") }
        }
        return File(_path).readText(charset)
    }

    fun saveFile(value: String, charset: Charset = _charset) {
        File(_path).writer(charset).use {
            it.write(value)
        }
    }
}